package cn.zn.modules.signature.controller;

import cn.zn.framework.common.utils.PageInUtils;
import cn.zn.framework.common.utils.PageUtils;
import cn.zn.framework.common.utils.R;
import cn.zn.modules.signature.entity.HtmlsignatureEntity;
import cn.zn.modules.signature.service.HtmlsignatureService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;


/**
 * @author zn
 * @email zhunahao@qq.com
 * @date 2020-01-07 09:39:20
 */
@RestController
@RequestMapping("api/signature")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class HtmlsignatureController {

    final private HtmlsignatureService htmlsignatureService;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("signature:htmlsignature:list")
    public R list(PageInUtils<HtmlsignatureEntity> pageIn, @RequestBody HtmlsignatureEntity htmlsignature) {

        PageUtils pageUtils = htmlsignatureService.queryPage(htmlsignature, pageIn.getPageObj());

        return R.ok().put("page", pageUtils);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{documentid}")
//    @RequiresPermissions("signature:htmlsignature:info")
    public R info(@PathVariable("documentid") String documentid) {
        HtmlsignatureEntity htmlsignature = htmlsignatureService.getById(documentid);

        return R.ok().put("htmlsignature", htmlsignature);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("signature:htmlsignature:save")
    public R save(@RequestBody HtmlsignatureEntity htmlsignature) {
        htmlsignatureService.save(htmlsignature);

        return R.ok().put("success", true);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("signature:htmlsignature:update")
    public R update(@RequestBody HtmlsignatureEntity htmlsignature) {
        htmlsignatureService.updateById(htmlsignature);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("signature:htmlsignature:delete")
    public R delete(@RequestBody String[] documentids) {
        htmlsignatureService.removeByIds(Arrays.asList(documentids));

        return R.ok();
    }

}
